package tests;
import static org.junit.Assert.*;

import java.util.HashMap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import dao.DaoException;
import dao.TemplateSqlDao;
import static org.mockito.Mockito.*;

/**
 * This class tests the TemplateSqlDao DB operations that return a value
 * by mocking. 
 * 
 * @author b_aldosa
 * @since June 16, 2013
 *
 */

public class TestDBTemplateSqlDao {

	TemplateSqlDao SUT;
	HashMap<String, String> properties;
	HashMap<Integer, String[]> properties2;
	
	
	/**
	 * This method is called before each test case, it creates a new FilterSqlDao object and 
	 * properties hash maps used in test cases.
	 */
	
	@Before
	public void setUp()
	{
		SUT =mock(TemplateSqlDao.class);
		properties=new HashMap<String,String>();
		properties2=new HashMap<Integer, String[]>();
	}
	
	/**
	 * This method is called after each test case to nullify the created objects
	 */
	@After
	public void tearDows()
	{
		SUT =null;
		properties=null;
		properties2=null;
	}
	
	/**
	 * This test case tests the Create method by checking the return value.
	 * @throws DaoException
	 */
	@Test
	public void testCreate() throws DaoException {
		when(SUT.create(properties)).thenReturn(1);
		assertEquals(1,SUT.create(properties));
	}
	
	/**
	 * This test case tests the load method by checking return value and 
	 * asserting that it is null.
	 * @throws DaoException
	 */
	@Test
	public void testLoad() throws DaoException {
		when(SUT.load(0)).thenReturn(properties);
		assertTrue(SUT.load(0).isEmpty());
	}

	/**
	 * This test case tests the Find by user id method by
	 * checking the return value and asserting that it is null
	 * @throws DaoException
	 */
	@Test
	public void testFindByUserId() throws DaoException {
		
		when(SUT.findByUserId(0)).thenReturn(properties2);
		assertTrue(SUT.findByUserId(0).isEmpty());
	}



}
